package 剑指Offer1;

import java.util.ArrayList;
import java.util.List;

public class _32二叉搜索树的第k大节点 {
    public class TreeNode {
       int val;
       TreeNode left;
       TreeNode right;
       TreeNode(int x) { val = x; }
    }

    private List<Integer> res = new ArrayList<>();
    public int kthLargest(TreeNode root, int k) {
        if(root == null) return 0;
        inorder(root);
        return res.get(res.size() - k);
    }

    private void inorder(TreeNode root){
        if(root == null) return;

        inorder(root.left);
        res.add(root.val);
        inorder(root.right);
    }

}
